package PokerGame;

import java.util.Random;

public class CardGame {

	protected Player[] player;
	protected int dealer;

	public CardGame(Player[] player) {
		this.player=player;
		dealer(player);
		whoWin(player);
		
		Watcher watcher = new Watcher();
		System.out.println(watcher.voice());
	}
	

	public void dealer(Player[] player) {
		for (int i = 0; i < player.length; i++) {
			player[i].setDealer(false);
		}
		Random r = new Random();
		int i = Math.abs(r.nextInt())%4;
		this.dealer=i;
		player[i].setDealer(true);

	}

	public boolean compare(Player player, Player dealer) {
		if (player.getResult() > dealer.getResult()) {
			return true;
		} else
			return false;
	}

	public void whoWin(Player[] player) {
		int dealer = -1;
		for (int i = 0; i < player.length; i++) {
			if (player[i].isDealer()) {
				dealer = i;
			}
		}

		for (int i = 0; i < player.length; i++) {
			if (i != dealer) {
				player[i].setWin(compare(player[i], player[dealer]));
			}
		}

	}
}
